package com.ihr360.excel.aggregatemodule.service.fallback;

import com.ihr360.commons.exception.Ihr360SpreadSheetAsynException;
import com.ihr360.commons.exception.Ihr360SpreadSheetInterruptException;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.excel.aggregatemodule.service.ExcelCloudService;
import com.ihr360.excel.vo.ImportResult;
import com.ihr360.excel.vo.ProgressContext;
import com.ihr360.excel.vo.ProgressResult;
import com.ihr360.sharedservice.api.DataCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExcellServiceFallback implements ExcelCloudService {


    @Autowired
    private DataCacheService dataCacheService;

    @Override
    public void handleExcel(ProgressContext progressContext) {
        throw new Ihr360SpreadSheetAsynException(progressContext.getProgressKey(), "处理文件失败！");
    }

    @Override
    public void saveExcelProcessorJournal(ProgressContext progressContext, String errorMsg) {
        throw new Ihr360SpreadSheetAsynException(progressContext.getProgressKey(), errorMsg);
    }

    @Override
    public ProgressResult getProgressResult(ProgressContext progressContext) {
        throw new Ihr360SpreadSheetInterruptException("获取进度失败！");
    }

    @Override
    public ImportResult getImportResult(ProgressContext progressContext) {
        throw new Ihr360SpreadSheetAsynException(progressContext.getProgressKey(), "获取正确数据失败！");
    }

    @Override
    public ResultInfo interruptProgress(ProgressContext progressContext) {
        dataCacheService.remove(progressContext.getProgressKey());
        return new ResultInfo.Builder<>().success();
    }

    @Override
    public String getErrorFileId(ProgressContext progressContext) {
        throw new Ihr360SpreadSheetAsynException(progressContext.getProgressKey(), "获取错误文件失败");
    }
}
